#include "GapStateEchoPend.h"
#include "GapStateMap.h"
//#include "common.pb.h"
//#include "GAP.pb.h"
#include "MgwGapProxy.h"

namespace tsc
{
namespace sgw
{

//using namespace GatewayApplicationPart;
//using namespace ProtocolsCommon;

/*******************************************************************************
 *
 * Constructor
 *
 ******************************************************************************/
GapStateEchoPend::GapStateEchoPend() :
	GapStateBase("EchoPend")
{

} // GapStateEchoPend::GapStateEchoPend

/*******************************************************************************
 *
 * Destructor
 *
 ******************************************************************************/
GapStateEchoPend::~GapStateEchoPend()
{

} // GapStateConnected::~GapStateConnected

//===================================================================
GapStateEchoPend* GapStateEchoPend::instance()
{
	static GapStateEchoPend mInstance;
	return &mInstance;
}

//===================================================================
void
GapStateEchoPend::handleEventGapT8221Expired(
    GapGenerator* gapGen,
    GapEventT8221Expired* event,
    EventData*& eventData)
{
    // TODO logging

    // TODO release all contexts

    gapGen->changeState(GapStateMap::mpStateIdle);

    EventData::deleteEvent(eventData);
}

//===================================================================
void
GapStateEchoPend::handleEventGapEchoResponse(
    GapGenerator* gapGen,
    GapEventEchoResp* event,
    EventData*& eventData)
{
    // TODO logging

    // stop timer which guards waiting for EchoResp
    gapGen->cancelT8221();
    // start timer which triggers sending next EchoReq
    gapGen->startT823();

    gapGen->changeState(GapStateMap::mpStateConnected);

    EventData::deleteEvent(eventData);
}

} // namespace sgw
} // namespace tsc
